using System.Collections.Generic;
using XDFLib.Extensions;


namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_List_IntegerToBoolean_RT : RT_Node
    {
        public RT_ValueListPort IntegerList_RT;

        public RT_ValueListPort BooleanList_RT;

        public Node_List_IntegerToBoolean_RT(Node_List_IntegerToBoolean sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            IntegerList_RT = new RT_ValueListPort(EPortIOType.Input, sourceData.IntegerList, this);

            BooleanList_RT = new RT_ValueListPort(EPortIOType.Output, sourceData.BooleanList, this);
            BooleanList_RT.OnGetValueList = GetBooleanList;
        }

        public List<AValue> GetBooleanList(DAG_Executor executor)
        {
            var vList = BooleanList_RT.GetValueList(executor);

            var info = executor.GetExeInfoOfNode(this) as List_Convert_Info;
            if (info == null)
            {
                info = new List_Convert_Info();
                executor.SetExeInfoOfNode(this, info);
            }
            else
            {
                info.ResultList.Clear();
            }

            info.ResultList.Resize(vList.Count, () => { return new Value_Boolean(false); });

            for (int i = 0; i < vList.Count; i++)
            {
                bool currBool = vList[i].ToBoolean().Item2;
                info.ResultList[i].SetBoolean(currBool);
            }
            return info.ResultList;
        }
    }
}